package edu.xhu.communityantiepidemicsystemback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.xhu.communityantiepidemicsystemback.dto.*;
import edu.xhu.communityantiepidemicsystemback.entity.Filing;
import edu.xhu.communityantiepidemicsystemback.mapper.FilingMapper;
import edu.xhu.communityantiepidemicsystemback.service.IFilingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcx
 * @since 2022-06-20
 */
@Service
public class FilingServiceImpl extends ServiceImpl<FilingMapper, Filing> implements IFilingService {

    @Override
    public IPage<Filing> selectFileList(Query query) {
        Page<Filing> queryPage = new Page<>();
        queryPage.setCurrent(query.getPageNO());
        queryPage.setSize(query.getPageSize());
        return this.page(queryPage);
    }
    //模糊查询
    @Override
    public IPage<Filing> fuzzyFilingInfo(Fuzzy fuzzy) {
        Page<Filing> page=new Page<>();
        page.setCurrent(fuzzy.getPageNO());
        page.setSize(fuzzy.getPageSize());
        QueryWrapper<Filing> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(fuzzy.getSelect(),fuzzy.getSearchStr());
        return this.page(page,queryWrapper);
    }

    @Override
    public boolean addFile(CreateFile createFile) {
        Filing filing=new Filing();
        BeanUtils.copyProperties(createFile,filing);


        filing.setName(createFile.getName());
        filing.setCreateTime(LocalDateTime.now());
        filing.setCreator("system");
        System.out.println(filing);
        return this.save(filing);
    }

    @Override
    public boolean delFile(Integer id) {
        return this.removeById(id);
    }

    @Override
    public boolean updateFile(UpdateFile updateFile) {
        Filing filing=new Filing();
        BeanUtils.copyProperties(updateFile,filing);
        filing.setUpdateTime(LocalDateTime.now());
        filing.setOperator("system");

        return this.updateById(filing );
    }
}
